<?php
class AftermarketAction extends MemberAction{
	/*
	  thtype 退货类型
	  0.默认
	  1.退货
	  2.换货
	  3.退款
	*/
	public function _initialize(){
		parent::_initialize();
	}
	
    public function index(){
	   
	   $state = $this->_get('state');
	    
	   $map = array('o.site_id' => __SITEID__,'s.thtype'=>array('neq',0),'s.member_id'=>$this->memberInfo['id']);
	   
	   if($state == 1){
	     $map['thtype'] = 1;
	   }elseif($state == 2){
	     $map['thtype'] = 2;
	   }elseif($state == 3){
	     $map['thtype'] = 3;
	   }
	   
	   $saleDB = D('sale');
	   $count = $saleDB->alias('s')->join('INNER JOIN __ORDER__ as o on o.id = s.order_id')->where($map)->getField('count(distinct(s.id)) as tp');
	   
	   //实例化分页类
		import ( 'ORG.Util.Page' );
		$p=new Page($count,5);
		
		$data = $saleDB->alias('s')->join('LEFT JOIN __ORDER__ as o on o.id = s.order_id')->where($map)->order('create_time DESC')->limit($p->firstRow.',
'.$p->listRows) -> Field('s.id as sale_id,s.*') -> select();
	   //商品详情
	   foreach($data as $k=>$v){
	     $data[$k]['product'] = M('product')->where(array('id'=>$v['product_id']))->find();
	   }
       $pages=$p->show();
	   $this->assign('list',$data);
	   $this->assign('pages',$pages);
	   $this->assign('state',$state);
	   $this->display(); 
	}
}